﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Xml;
using System.Text;

namespace Xiaov.SmartWeb.Application.TZGC.GCLB
{
    public partial class Gclbgl : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindGclb();
            }
        }

        protected void BindGclb()
        {
            string sql = "select * from yt_gclbb order by xh";
            DataSet ds = Maticsoft.DBUtility.DbHelperOra.Query(sql);
            ddl_gclb.DataSource = ds.Tables[0];
            ddl_gclb.DataTextField = "lbmc";
            ddl_gclb.DataValueField = "lbbm";
            ddl_gclb.DataBind();
        }

        protected void btn_save_Click(object sender, EventArgs e)
        {
            #region 已分类工程调整为未分类
            if (HDGcWgs.Value != null && HDGcWgs.Value != "" && HDGcWgs.Value != "0")
            {
                XmlDocument xmlInfo = new XmlDocument();
                xmlInfo.LoadXml(HDGcWgs.Value);
                XmlElement xmlElement = xmlInfo["table"]["newRow"];
                if (xmlElement != null)
                {
                    StringBuilder sqlSB = new StringBuilder();
                    sqlSB.Append("begin ");
                    foreach (XmlNode item in xmlElement.ChildNodes)
                    {
                        sqlSB.Append(string.Format("update yt_gcb set gclb = '{0}' where gcid = '{1}';",
                            null, item["gcid"].InnerText.Replace("\r\n", "")));
                    }
                    sqlSB.Append("null;end;");
                    Maticsoft.DBUtility.DbHelperOra.ExecuteSql(sqlSB.ToString());
                }
            }
            #endregion
            #region 未分类工程进行分类
            if (HDGcYgs.Value != null && HDGcYgs.Value != "" && HDGcYgs.Value != "0")
            {
                XmlDocument xmlInfo = new XmlDocument();
                xmlInfo.LoadXml(HDGcYgs.Value);
                XmlElement xmlElement = xmlInfo["table"]["newRow"];
                if (xmlElement != null)
                {
                    StringBuilder sqlSB = new StringBuilder();
                    sqlSB.Append("begin ");
                    foreach (XmlNode item in xmlElement.ChildNodes)
                    {
                        sqlSB.Append(string.Format("update yt_gcb set gclb = '{0}' where gcid = '{1}' ;",
                            ddl_gclb.Value, item["gcid"].InnerText.Replace("\r\n", "")));
                    }
                    sqlSB.Append("null;end;");
                    Maticsoft.DBUtility.DbHelperOra.ExecuteSql(sqlSB.ToString());
                }
            }
            #endregion
            this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "提示", "<Script Language='JavaScript'>window.alert('保存成功！')</script>");
        }
    }
}